package com.losl.framework.security;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * 认证失败处理类
 */
@Component
public class AuthenticationFailHandler implements AuthenticationEntryPoint, Serializable {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        String uri = request.getRequestURI();
        String message="请求访问:"+uri+",认证失败，无法访问";
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/text");
        response.setCharacterEncoding("utf-8");
        response.getWriter().println(uri);
    }
}
